<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:m="http://www.ol4jsf.org"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:o="http://openfaces.org/">


	<h:panelGroup rendered="#{not interactiveViewerHelper.rrrHelper.editingRestrictions and not interactiveViewerHelper.rrrHelper.editingResponsibilities}">
		<h:form rendered="#{interactiveViewerHelper.allowEditing}">
			<a4j:jsFunction name="editingRestrictionsFun"
			rendered="#{not interactiveViewerHelper.rrrHelper.editingRestrictions}"
			reRender="panelRestrictions">
				<f:setPropertyActionListener value="#{true}" target="#{interactiveViewerHelper.rrrHelper.editingRestrictions}" />
			</a4j:jsFunction>
			
			<a4j:jsFunction name="cancelRestrictionChangesFun"
			action="#{interactiveViewerHelper.rrrHelper.cancelRestrictionChanges}"
			rendered="#{interactiveViewerHelper.rrrHelper.editingRestrictions}"
			reRender="panelRestrictions">
			</a4j:jsFunction>
			
			<a4j:jsFunction name="applyRestrictionChangesFun"
			action="#{interactiveViewerHelper.rrrHelper.applyRestrictionChanges}"
			rendered="#{interactiveViewerHelper.rrrHelper.editingRestrictions}"
			reRender="panelRestrictions,transactionCnts"
			oncomplete="if ( #{facesContext.maximumSeverity != null} ) #{rich:component('msgPanel')}.show();">
			</a4j:jsFunction>
			
			<a4j:jsFunction name="addNewRestrictionFun"
			rendered="#{interactiveViewerHelper.rrrHelper.editingRestrictions}"
			oncomplete="#{rich:component('panelModiRestrictions')}.show(); #{rich:component('selectPartyPanel')}.show()">
				<f:setPropertyActionListener target="#{personHelper.addingToList}" value="#{true}" />
				<f:setPropertyActionListener target="#{personHelper.returnValueField}" value="interactiveViewerHelper.rrrHelper.selectedPerson" />
				<f:setPropertyActionListener target="#{personHelper.addToListMethod}" value="interactiveViewerHelper.rrrHelper.addNewRestriction" />
				<f:setPropertyActionListener target="#{personHelper.reRenderComponents}" value="#{rich:clientId('newRestrictionsTable')}" />
				
				<f:setPropertyActionListener target="#{legalPersonHelper.addingToList}" value="#{true}" />
				<f:setPropertyActionListener target="#{legalPersonHelper.returnValueField}" value="interactiveViewerHelper.rrrHelper.selectedPerson" />
				<f:setPropertyActionListener target="#{legalPersonHelper.addToListMethod}" value="interactiveViewerHelper.rrrHelper.addNewRestriction" />
				<f:setPropertyActionListener target="#{legalPersonHelper.reRenderComponents}" value="#{rich:clientId('newRestrictionsTable')}" />
			</a4j:jsFunction>
			
			<a4j:jsFunction name="modifySelectedRestrictionsFun"
			action="#{interactiveViewerHelper.rrrHelper.modifySelectedRestrictions}"
			rendered="#{not empty interactiveViewerHelper.rrrHelper.parcelRestrictionsList and interactiveViewerHelper.rrrHelper.editingRestrictions}"
			reRender="responsibilitiesTable,newRestrictionsTable"
			oncomplete="#{rich:component('panelModiRestrictions')}.show();">
			</a4j:jsFunction>
			
			<a4j:jsFunction name="deleteSelectedRestrictionsFun"
			rendered="#{not empty interactiveViewerHelper.rrrHelper.parcelRestrictionsList and interactiveViewerHelper.rrrHelper.editingRestrictions}"
			action="#{interactiveViewerHelper.rrrHelper.deleteSelectedRestrictions}"
			reRender="responsibilitiesTable,newRestrictionsTable">
			</a4j:jsFunction>
		</h:form>
	
		<ui:include src="selectedZoneTlb.xhtml" />

		<h:panelGroup rendered="#{interactiveViewerHelper.selectedParcel == null}">
			<div align="center">
				<h:outputText value="#{messages['txt.no_zone_or_parcel_selected']}" />
			</div>
		</h:panelGroup>
		<h:panelGroup rendered="#{interactiveViewerHelper.selectedParcel != null}">
			<rich:toolBar height="20" itemSeparator="line" rendered="#{interactiveViewerHelper.allowEditing}">
				<rich:toolBarGroup>
					<h:panelGroup>
						<o:commandButton type="button" onclick="editingRestrictionsFun();"
						disabled="#{interactiveViewerHelper.rrrHelper.editingRestrictions}">
							<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
								<span style="white-space:nowrap">
									#{messages['dataentry.mutate_restrictions.btn_edit']}
								</span>
							</rich:toolTip>
							<h:graphicImage value="/img/edit.gif" />
						</o:commandButton>
		
						<o:commandButton type="button" onclick="cancelRestrictionChangesFun();"
						disabled="#{not interactiveViewerHelper.rrrHelper.editingRestrictions}">
							<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
								<span style="white-space:nowrap">
									#{messages['dataentry.mutate_restrictions.btn_cancel']}
								</span>
							</rich:toolTip>
							<h:graphicImage value="/img/cancel-icon.png" width="16px" height="16px" />
						</o:commandButton>
		
						<o:commandButton type="button" onclick="applyRestrictionChangesFun();"
						disabled="#{not interactiveViewerHelper.rrrHelper.editingRestrictions}">
							<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
								<span style="white-space:nowrap">
									#{messages['dataentry.mutate_restrictions.btn_save']}
								</span>
							</rich:toolTip>
							<h:graphicImage value="/img/save-icon.png" width="16px" height="16px" />
						</o:commandButton>
					</h:panelGroup>
				</rich:toolBarGroup>
				
				<rich:toolBarGroup>
					<h:panelGroup>
						<o:commandButton type="button" onclick="addNewRestrictionFun();"
						disabled="#{not interactiveViewerHelper.rrrHelper.editingRestrictions}">
							<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
								<span style="white-space:nowrap">
									#{messages['dataentry.mutate_restrictions.btn_add_new_one']}
								</span>
							</rich:toolTip>
							<h:graphicImage value="/img/add-icon.png" />
						</o:commandButton>
						
						<o:commandButton type="button" onclick="modifySelectedRestrictionsFun();"
						disabled="#{empty interactiveViewerHelper.rrrHelper.parcelRestrictionsList or not interactiveViewerHelper.rrrHelper.editingRestrictions}">
							<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
								<span style="white-space:nowrap">
									#{messages['dataentry.mutate_restrictions.btn_modify_selected']}
								</span>
							</rich:toolTip>
							<h:graphicImage value="/img/edit.gif" />
						</o:commandButton>
						
						<o:commandButton type="button" onclick="deleteSelectedRestrictionsFun();"
						disabled="#{empty interactiveViewerHelper.rrrHelper.parcelRestrictionsList or not interactiveViewerHelper.rrrHelper.editingRestrictions}">
							<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
								<span style="white-space:nowrap">
									#{messages['dataentry.mutate_restrictions.btn_delete_selected']}
								</span>
							</rich:toolTip>
							<h:graphicImage value="/img/delete-icon.png" />
						</o:commandButton>
					</h:panelGroup>
				</rich:toolBarGroup>
			</rich:toolBar>
			
			<div align="center" style="height:450px;" class="contentRestrictions">
				<br />
				<strong>#{messages['dataentry.mutate_restrictions.current']}</strong>
				<rich:separator lineType="solid"/>
				<br />
				<h:panelGroup id="restrictionsTable">
					<h:panelGroup rendered="#{not empty interactiveViewerHelper.rrrHelper.parcelRestrictionsList}">
						<rich:dataTable
						value="#{interactiveViewerHelper.rrrHelper.parcelRestrictionsGroups}"
						var="group" rowKeyVar="row"
						cellspacing="1" rows="13"
						style="vertical-align:baseline;">
							<f:facet name="header">
								<rich:columnGroup>
									<rich:column rendered="#{interactiveViewerHelper.rrrHelper.editingRestrictions}">
										<h:outputText value="#{messages['dataentry.mutate_rrr.edit']}"/>
									</rich:column>
									<rich:column>
										<h:outputText value="#{messages['dataentry.mutate_rrr.party']}"/>
									</rich:column>
									<rich:column>
										<h:outputText value="#{messages['dataentry.mutate_restrictions.type']}"/>
									</rich:column>
									<rich:column style="text-align:right;">
										<h:outputText value="#{messages['dataentry.mutate_rrr.share']}"/>
									</rich:column>
								</rich:columnGroup>
							</f:facet>
							
							<rich:column rendered="#{interactiveViewerHelper.rrrHelper.editingRestrictions}">
								<rich:spacer/>
							</rich:column>
							<rich:column colspan="2" style="font-weight:bold;background-color:#F1F1F1;">
								<h:outputText value="#{messages['dataentry.mutate_rrr.total']} #{messages[group.rrrType].toUpperCase()}"/>
							</rich:column>
							<rich:column style="text-align:right;font-weight:bold;background-color:#F1F1F1;">
								<h:outputText value="#{group.sumShares}" rendered="#{group.sumShares.one}" />
								<h:outputText value="#{group.sumShares}" style="color:Red;" rendered="#{not group.sumShares.one}" />
							</rich:column>
							
							<rich:subTable value="#{group.rrrList}" var="rrr">
								<rich:column rendered="#{interactiveViewerHelper.rrrHelper.editingRestrictions}">
									<h:selectBooleanCheckbox value="#{rrr.selected}"/>
								</rich:column>
								<rich:column>
									<h:outputText value="#{rrr.owner}"/>
								</rich:column>
								<rich:column>
									<h:outputText value="#{messages[rrr.rrrType.name()]}" />
								</rich:column>
								<rich:column style="text-align:right;">
									<h:outputText value="#{rrr.shareString}"/>
								</rich:column>
							</rich:subTable>
						</rich:dataTable>
						<br />
						<br />
					</h:panelGroup>
					
					<h:panelGroup rendered="#{empty interactiveViewerHelper.rrrHelper.parcelRestrictionsList}">
						<h:outputText value="#{messages['dataentry.mutate_restrictions.no']}" />
						<br />
					</h:panelGroup>
				</h:panelGroup>
				<br/>
				<br/>
			</div>
		</h:panelGroup>
	
		<h:panelGroup rendered="#{interactiveViewerHelper.selectedParcel != null and interactiveViewerHelper.allowEditing}">
			<rich:modalPanel id="panelModiRestrictions" width="550" height="530" zindex="10500">
				<f:facet name="header">
					<h:panelGroup>
						<h:outputText value="#{messages['dataentry.mutate_restrictions.new']}"></h:outputText>
					</h:panelGroup>
				</f:facet>
				<f:facet name="controls">
					<h:panelGroup>
						<h:graphicImage value="/img/close.png" styleClass="hidelink"
						onclick="modiRestrictionsCancel()" />
					</h:panelGroup>
				</f:facet>
				
				<h:form>
					<a4j:jsFunction name="addNewFun" oncomplete="#{rich:component('selectPartyPanel')}.show()">
						<f:setPropertyActionListener target="#{personHelper.addingToList}" value="#{true}" />
						<f:setPropertyActionListener target="#{personHelper.returnValueField}" value="interactiveViewerHelper.rrrHelper.selectedPerson" />
						<f:setPropertyActionListener target="#{personHelper.addToListMethod}" value="interactiveViewerHelper.rrrHelper.addNewRestriction" />
						<f:setPropertyActionListener target="#{personHelper.reRenderComponents}" value="#{rich:clientId('newRestrictionsTable')}" />
						
						<f:setPropertyActionListener target="#{legalPersonHelper.addingToList}" value="#{true}" />
						<f:setPropertyActionListener target="#{legalPersonHelper.returnValueField}" value="interactiveViewerHelper.rrrHelper.selectedPerson" />
						<f:setPropertyActionListener target="#{legalPersonHelper.addToListMethod}" value="interactiveViewerHelper.rrrHelper.addNewRestriction" />
						<f:setPropertyActionListener target="#{legalPersonHelper.reRenderComponents}" value="#{rich:clientId('newRestrictionsTable')}" />
					</a4j:jsFunction>
					
					<a4j:jsFunction name="acceptRestrictionsModificationFun"
					action="#{interactiveViewerHelper.rrrHelper.acceptRestrictionsModification}"
					reRender="restrictionsTable, newRestrictionsTable"
					oncomplete="if (#{facesContext.maximumSeverity == null}) #{rich:component('panelModiRestrictions')}.hide();">
					</a4j:jsFunction>
					
					<a4j:jsFunction name="modiRestrictionsCancelFun" immediate="true" ajaxSingle="true"
					action="#{interactiveViewerHelper.rrrHelper.cancelRestrictionsModification}"
					reRender="restrictionsTable, newRestrictionsTable"
					oncomplete="#{rich:component('panelModiRestrictions')}.hide();">
					</a4j:jsFunction>
		
					<rich:toolBar itemSeparator="grid">
						<rich:toolBarGroup>
							<o:commandButton type="button" onclick="addNewFun();">
								<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
									<span style="white-space:nowrap">
										#{messages['dataentry.mutate_rrr.btn_add_new']}
									</span>
								</rich:toolTip>
								<h:graphicImage value="/img/add-icon.png" />
							</o:commandButton>
						</rich:toolBarGroup>
						
						<rich:toolBarGroup location="right">
							<h:panelGroup>
								<o:commandButton type="button" onclick="acceptRestrictionsModificationFun();">
									<rich:toolTip followMouse="true" direction="bottom-left" showDelay="500" styleClass="tooltip">
										<span style="white-space:nowrap">
											#{messages['dataentry.mutate_rrr.btn_accept_changes']}
										</span>
									</rich:toolTip>
									<h:graphicImage value="/img/accept-icon.png" width="16px" height="16px" />
								</o:commandButton>
				
								<o:commandButton type="button" onclick="modiRestrictionsCancelFun()">
									<rich:toolTip followMouse="true" direction="bottom-left" showDelay="500" styleClass="tooltip">
										<span style="white-space:nowrap">
											#{messages['dataentry.mutate_rrr.btn_cancel_changes']}
										</span>
									</rich:toolTip>
									<h:graphicImage value="/img/cancel-icon.png" width="16px" height="16px" />
								</o:commandButton>
							</h:panelGroup>
						</rich:toolBarGroup>
					</rich:toolBar>
					
					<br/>
					
					<div align="center">
						<h:panelGroup id="newRestrictionsTable">
							<h:panelGroup rendered="#{not empty interactiveViewerHelper.rrrHelper.newParcelRestrictionsList}">
								<div style="height:400px;" class="contentRestrictions">
								<rich:dataTable value="#{interactiveViewerHelper.rrrHelper.newParcelRestrictionsList}" var="newRestriction" rowKeyVar="row">
									<f:facet name="header">
										<rich:columnGroup>
											<rich:column breakBefore="true" rowspan="2">
												<h:outputText value="#{messages['dataentry.mutate_rrr.party']}"/>
											</rich:column>
											<rich:column rowspan="2">
												<h:outputText value="#{messages['dataentry.mutate_restrictions.type']}"/>
											</rich:column>
											<rich:column colspan="2">
												<h:outputText value="#{messages['dataentry.mutate_rrr.share']}"/>
											</rich:column>
											<rich:column breakBefore="true">
												<h:outputText value="#{messages['dataentry.mutate_rrr.numerator']}"/>
											</rich:column>
											<rich:column>
												<h:outputText value="#{messages['dataentry.mutate_rrr.denominator']}"/>
											</rich:column>
										</rich:columnGroup>
									</f:facet>
									
									<rich:column>
										<a4j:commandLink id="editNameLink" oncomplete="#{rich:component('selectPartyPanel')}.show()">
											<f:setPropertyActionListener target="#{interactiveViewerHelper.rrrHelper.selectedRestriction}" value="#{newRestriction}"/>
											
											<f:setPropertyActionListener target="#{personHelper.addingToList}" value="#{false}" />
											<f:setPropertyActionListener target="#{personHelper.returnValueField}" value="interactiveViewerHelper.rrrHelper.selectedPerson" />
											<f:setPropertyActionListener target="#{personHelper.reRenderComponents}" value="#{rich:clientId('newRestrictionsTable')}" />
											
											<f:setPropertyActionListener target="#{legalPersonHelper.addingToList}" value="#{false}" />
											<f:setPropertyActionListener target="#{legalPersonHelper.returnValueField}" value="interactiveViewerHelper.rrrHelper.selectedPerson" />
											<f:setPropertyActionListener target="#{legalPersonHelper.reRenderComponents}" value="#{rich:clientId('newRestrictionsTable')}" />
		
											<h:outputText value="#{newRestriction.owner}"/>
										</a4j:commandLink>
									</rich:column>
									<rich:column>
										<h:selectOneMenu value="#{newRestriction.rrrType}" converter="#{uiConverters.restrictionType}">
											<f:selectItems value="#{uiConverters.restrictionType.valueList}"/>
										</h:selectOneMenu>
									</rich:column>
									<rich:column style="text-align:right;">
										<rich:inputNumberSpinner value="#{newRestriction.share.numerator}" minValue="0" maxValue="100" step="1" style=" width : 39px;"/>
									</rich:column>
									<rich:column style="text-align:right;">
										<rich:inputNumberSpinner value="#{newRestriction.share.denominator}" minValue="0" maxValue="100" step="1" style=" width : 39px;"/>
									</rich:column>
								</rich:dataTable>
								</div>
								<br />
								<br />
							</h:panelGroup>
							<h:panelGroup rendered="#{empty interactiveViewerHelper.rrrHelper.newParcelRestrictionsList}">
								<div align="center">
									<h:outputText value="#{messages['dataentry.mutate_restrictions.no_new']}" />
								</div>
							</h:panelGroup>
						</h:panelGroup>
					</div>
				</h:form>
			</rich:modalPanel>
		</h:panelGroup>
	</h:panelGroup>
</ui:composition>
